package util
{
	public class ValidatorUtil
	{
		public function ValidatorUtil()
		{
		}
		
		public static function equalsIgnoreCase(char1:String,char2:String):Boolean{  
            return char1.toLowerCase() == char2.toLowerCase();  
        }
        
        public static function equals(char1:String,char2:String):Boolean{  
            return char1 == char2;  
        }
		
		public static function trim(char:String):String{  
            if(char == null){  
                return null;  
            }  
            return rtrim(ltrim(char));  
        }  
		
		public static function ltrim(char:String):String{  
            if(char == null){  
                return null;  
            }  
            var pattern:RegExp = /^\s*/;    
            return char.replace(pattern,"");   
        }   
           
  
        public static function rtrim(char:String):String{   
            if(char == null){   
                return null;   
            }   
            var pattern:RegExp = /\s*$/;    
            return char.replace(pattern,"");   
        }   

		public static function isNumber(char:String):Boolean{  
            if(char == null){  
                return false;  
            }  
            return !isNaN(Number(char));  
        }  

		public static function isInteger(char:String):Boolean{  
            if(char == null){  
                return false;  
            }  
            char = trim(char);  
            var pattern:RegExp = /^[-\+]?\d+$/;   
            var result:Object = pattern.exec(char);  
            if(result == null) {  
                return false;  
            }  
            return true;  
        }
        
		public static function isURL(char:String):Boolean{  
            if(char == null){  
                return false;  
            }  
            char = trim(char).toLowerCase();  
            var pattern:RegExp = /^http:\/\/[A-Za-z0-9]+\.[A-Za-z0-9]+[\/=\?%\-&_~`@[\]\':+!]*([^<>\"\"])*$/;   
            var result:Object = pattern.exec(char);  
            if(result == null) {
                return false;  
            }  
            return true;  
        }          

		public static function isEmail(char:String):Boolean{  
            if(char == null){  
                return false;  
            }  
            char = trim(char);  
            var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;   
            var result:Object = pattern.exec(char);
            if(result == null) {  
                return false;  
            }  
            return true;  
        }
        
		public static function beginsWith(char:String, prefix:String):Boolean{             
            return (prefix == char.substring(0, prefix.length));   
        }   
           
        public static function endsWith(char:String, suffix:String):Boolean{   
            return (suffix == char.substring(char.length - suffix.length));   
        }   
             
        public static function remove(char:String,remove:String):String{   
            return replace(char,remove,"");   
        }   
         
        public static function replace(char:String, replace:String, replaceWith:String):String{            
            return char.split(replace).join(replaceWith);   
        } 

        public static function isValidDate(d:String):Boolean{
        	if(d==null)return true;
        	if(d.length!=10){
        		return false;
        	}
        	if(d.charAt(4)!="-"){
        		return false;
        	}
        	if(d.charAt(7)!="-"){
        		return false;
        	}
        	
        	var dt:String=d.substring(0,4) +"-"+d.substring(5,7) +"-"+d.substring(8,10);	
        	var pattern:RegExp = /(([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29)/;   
            var result:Object = pattern.exec(dt);
            if(result == null) {  
               return false;  
            }  
            return true;		
        } 
        
        public static function formatDate(d:String):String{
        	if(!isValidDate(d))return "";
        	return d.substring(8,10) +"/"+d.substring(5,7)+"/"+d.substring(0,4) ;		
        }                        


	}
}